<?php




namespace App\Http\Controllers\Api\Site;


use App\Http\Controllers\Api\BasicController;
use App\Models\Site\ArticleReaded;
use App\Models\Site\SiteArticle;
use Jiannei\Response\Laravel\Support\Facades\Response;

class ArticleController extends BasicController
{


    /**
     * @api {get} /site/article 文章列表
     * @apiName SiteArticleIndex
     * @apiGroup SiteArticle
     *
     * @apiParam {number} cate_id 分类ID 1=平台公告
     *
     */
    public function index($cate_id=0)
    {
        $sk=$this->request->input('sk');
        $result = (new SiteArticle())->getList($cate_id,$this->uid(),$sk);
        return Response::success($result);
    }

    /**
     * @api {get} /site/article/notice 系统公告
     * @apiName SiteArticleNotice
     * @apiGroup SiteArticle
     *
     */
    public function notice()
    {
        $result = SiteArticle::where('cate_id', 1)->orderByDesc('id')->first();
        return Response::success($result);
    }


    /**
     * @api {get} /site/article/1 文章详情
     * @apiName SiteArticleShow
     * @apiGroup SiteArticle
     *
     * @apiParam {number} id 文章ID 1=关于我们2=用户协议3=隐私政策
     *
     */
    public function show($id)
    {
        $result = (new SiteArticle())->getDetail($id);
        if($result->cate_id==2){
            (new ArticleReaded())->read($this->uid(),$result->id);
        }
        return Response::success($result);
    }
}
